package model;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;

import javax.imageio.ImageIO;

public class RawImage implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -588802606903244597L;
	private String imgPath;
	transient private BufferedImage img;

	public BufferedImage getImage() {
		if(img == null){
			loadImage();
		}
		return img;
	}
	
	public String getImagePath(){
		return imgPath;
	}

	public int getHeight() {
		return img.getHeight();
	}

	public int getWidth() {
		return img.getWidth();
	}

	public RawImage(String path) {
		this.imgPath = path;// no setters, immutable object
		loadImage();
	}

	private void loadImage() {
		try {
			img = ImageIO.read(new File(imgPath));
		} catch (IOException e) // not exists || not accessible
		{
			System.out.println("Unable to load image: " + e.getMessage());
			img = new BufferedImage(128, 128, BufferedImage.TYPE_INT_RGB);// temp
																			// image
		}
	}

}
